<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Session;
use \think\Db;
class Formshowpic extends Common
{
	public function add(){
    $result = Db::name("clubs")->order('c_id')->select();
    
    $this->assign("clublist",$result);
		return $this->fetch();
	}

	/*public function edit($id){
		$result = Db::name("picture")->where('showpicid',$id)->find();
    $result2 = Db::name("club")->order('clubid')->select();
    $this->assign("clublist",$result2);
    $this->assign("showpic",$result);
    return $this->fetch();
	}*/public function jiekou(){

        $rs=Db::name('clubs')->select();
        return json($rs);
}



  public function addshowpic(){
    $info = '';
        if (request()->isPost()) {
          //创建数组，用video表的所有字段赋值
          $user_id=input('username');
          var_dump($user_id);
          $file = request()->file('pic');
          $data=array();
          if($file){
              $info = $file->rule('uniqid')->validate(['size'=>3000000,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'static'. DS .'posters');
            $data=[
                  'u_id'=>9,
                  'c_id'=>input('param.clubid'),
                  'pi_time'=>date('Y-m-d H:i:s'),
                  'pi_title'=>input('param.showpiccontent'),
                  'pi_pic'=>$info->getFilename(),
            ];
          }else{
            $this->error("未上传图片",'showpic/index');
          }
        $res=Db::name('pictures')->insert($data);
        
        //处理结果
        if ($res) {
          $this->success("添加晒图成功",'showpic/index');
        }
        else {
          $this->error("添加晒图失败",'showpic/index');
        }
      }
  }
	

	
	public function delShowpic($id){
    $result = Db::name('pictures')->where('pi_id',$id)->find();

    if($result['pi_pic']!='default.jpg'){
      if(file_exists(ROOT_PATH . 'public' . DS . 'static'. DS .'posters'.DS.$result['pi_pic'])){
              unlink(ROOT_PATH . 'public' . DS . 'static'. DS .'posters'.DS.$result['pi_pic']);
            }
    }
		if (Db::name("pictures")->where('pi_id',$id)->delete()) {
      $this->success('删除成功','showpic/index');
    }else 
    $this->error('删除失败','showpic/index');
	}
}